<template>
  <van-swipe
      :autoplay="3000"
      indicator-color="#1baeae"
  >
    <van-swipe-item
        v-for="(item,index) in list"
        :key="index"
    >
      <img
          :src="item.imageUrl"
          alt=""
          class="w-full h-full"
          @click="goTo(item)"
      >
    </van-swipe-item>
  </van-swipe>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import type {ISwipeItem} from "./types";


defineOptions({
  name: 'Swiper'
})

const router = useRouter();


interface IProps {
  list: ISwipeItem[]
}

defineProps<IProps>()
const goTo = (item: ISwipeItem) => {
  if (!item?.redirectUrl) {
    return;
  }
  if (item.redirectUrl.startsWith('/')) {
    router.push({path: item.redirectUrl})
  } else {
    window.open(item.redirectUrl)
  }
}
</script>